import { wxRequest } from '../../utils/server.js';  
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     device:{ },
     typeIndex:0,
     list:[], 
     imgUrl: app.globalData.imgUrl,
     uploadUrl: wx.getStorageSync('uploadUrl'),
  },

   
  onShow: function (options) {  
  
    this.getDeviceList()
  },

   
//获取校准记录列表
findQueueList:function(){       
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/dyeRecord/findCorrectList',
      method: 'POST',
      data:{
        devId: this.data.deviceList[this.data.typeIndex].id,
        pageNo: 1, 
        pageSize:20, 
      } 
    }, (res) => { 
      let list = res.list; 
      list.map(item=>{
        item.modifyDateText1=item.modifyDateText.substring(10,16)
      })
      var myDate=new Date();
      this.setData({
        list: list, 
        time:myDate.getHours()+':'+(myDate.getMinutes()<10?'0'+myDate.getMinutes():myDate.getMinutes())+':'+(myDate.getSeconds()<10?'0'+myDate.getSeconds():myDate.getSeconds())
      }); 
      
    }) 
  },
  

  //下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function () {
    this.setData({
      pageNo: 1
    })
    this.findQueueList();
  },
 
 
  //触底时，加载更多
  onReachBottom: function () {
    if (this.data.hasNextPage) { 
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.findQueueList();
    }
  },

  //搜索关键词
  seachInputConfirm: function (e) {    
    this.setData({
      pageNo: 1,
      keyword:e.detail.value
    })
    this.findQueueList();
  },
  
  seachBtn: function () {
    this.setData({
      pageNo: 1,
      keyword: this.data.keyword
    })
    this.findQueueList();
  },

  seachInputVal: function (e) { 
    var inputval = e.detail.value;
    console.log(e)
    this.setData({
      keyword: inputval
    })
  },

  //清空
  clearInput: function () {
    this.setData({
      keyword: ''
    })
    this.findQueueList();
  },
 


  bindPickerChange(e){
    var val=e.detail.value
    this.setData({
      typeIndex:val,
      pageNo: 1,
    },()=>{
      this.findQueueList();
    })
  },






  getDeviceList: function() {
    var params = {
      keyword: this.data.keyword, 
      pageNo: 1,
      state: 2,
      typeId: wx.getStorageSync('currentTypeId'),
      pageSize:100
    }
     
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/device/findList',
      method: 'POST',
      data:params
    }, (res) => {
      let list = res.list.map(item => {
        if(item.stoName) {
          item.note += ` - ${item.stoName}`;
        }

        if(item.stoCreateName) {
          item.note += ` - ${item.stoCreateName}`;
        }
        return item;
      });
      
      this.setData({
        deviceList: list, 
      },()=>{
        if(list.length>0){
          this.findQueueList() 
        }
        
      });
    })
  },













})